package com.competition.web.admin.service.impl;

import java.util.List;
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.competition.web.entity.User;
import com.competition.web.admin.mapper.UserMapper;
import com.competition.web.admin.service.IUserService;
import com.basic.service.impl.BaseServiceImpl;



@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

	

	RedisTemplate<String, String> redisTemplate;
	
	public UserServiceImpl(UserMapper userMapper) {
		super(userMapper);
	}
	
	
	@Autowired
	public void setRedisTemplate(RedisTemplate<String, String> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}



	@Override
	public <T, R> List<User> getDataByUserIds(List<T> list, Function<T, R> function) {
		// TODO Auto-generated method stub

		Integer[] ids = list.stream().map(e -> function.apply(e)).toArray(Integer[]::new);

		UserMapper userMapper = this.getBaseMapper();
		
		return userMapper.getDataByUserIds(ids);
	}





	@Override
	protected Class<User> getEntityClass() {
		// TODO Auto-generated method stub
		return User.class;
	}


	@Override
	public List<User> getUserListByStatus() {

		UserMapper userMapper = this.getBaseMapper();
		
		return userMapper.getUserListByStatus();
	}



//	@Override
//	public OrderBySearchParam getUserListByUserNameToSearch(OrderBySearchParam orderBySearchParam) {
//		
//		String userName = orderBySearchParam.getUserName();
//		
//		if (null == userName) {
//			return orderBySearchParam;
//		}
//		
//		List<User> users = this.userMapper.getUserIdsByUserName(userName);
//		
//		if (null == users) {
//			return orderBySearchParam;
//		}
//		
//		orderBySearchParam.setUserIds(users.stream().map(e->e.getId()).toArray(Integer[]::new));
//		
//		return orderBySearchParam;
//	}
//


//	@Override
//	public <S> S getStatisticsUser() {
//		
//		long startTime = GetTheZeroTimeStampOfTheDay.getCurrentZero();
//		
//		long endTime = GetTheZeroTimeStampOfTheDay.getEndTimeOfTheDay();
//		
//		long yesterdayStartTime = GetTheZeroTimeStampOfTheDay.getYesterdayZero();
//		
//		long time = System.currentTimeMillis();
//		
//		long thisMonthByStart = DateUtil.getMonthBegin(time);
//		
//		long thisMonthByEnd = DateUtil.getMonthEnd(time);
//		
//		
//		List<S> list = this.userMapper.getStatisticsUser(
//			startTime / 1000,
//			endTime / 1000,
//			yesterdayStartTime / 1000,
//			startTime / 1000,
//			thisMonthByStart,
//			thisMonthByEnd
//		);
//		
//		Map<Class<?>, Class<?>> map = new HashMap<>();
//		
//		map.put(Integer.class, int.class);
//		
//		String field = "newlyAddedByToday";
//		
//		return this.getS(map, list, field);
//	}



	@Override
	public <T, R> List<User> getDataByMarket(List<T> list, Function<T, R> function) {
		Integer[] ids = list.stream().map(e -> function.apply(e)).toArray(Integer[]::new);

		UserMapper mapper = this.getBaseMapper();
		return mapper.getDataByUserIds(ids);
	}



	
	


}
